


package jnpf.zc.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jnpf.base.ActionResult;
import jnpf.base.UserInfo;
import jnpf.base.entity.VisualdevEntity;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.engine.entity.FlowTaskEntity;
import jnpf.engine.enums.FlowStatusEnum;
import jnpf.exception.DataException;
import jnpf.exception.WorkFlowException;
import jnpf.htgl.service.ZcglHtglInfoService;
import jnpf.permission.entity.UserEntity;
import jnpf.util.*;
import jnpf.zc.entity.*;
import jnpf.zc.model.zcglzcdjinfo.*;
import jnpf.zc.service.ZcglZcdjAreaService;
import jnpf.zc.service.ZcglZcdjInfoService;
import jnpf.zc.service.ZcglZcdjPhotoService;
import jnpf.zc.service.ZcglZcdjWarrantService;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;


/**
 * 资产登记
 *
 * @版本： V3.2.0
 * @版权： 智果云科技（https://www.jnpfsoft.com）
 * @作者： JNPF开发平台组
 * @日期： 2024-12-19
 */
@Slf4j
@RestController
@Api(tags = "资产登记", value = "example")
@RequestMapping("/api/example/ZcglZcdjInfo")
public class ZcglZcdjInfoController {


    @Autowired
    private GeneraterSwapUtil generaterSwapUtil;

    @Autowired
    private ZcglHtglInfoService zcglHtglInfoService;


    @Autowired
    private UserProvider userProvider;

    @Autowired
    private ZcglZcdjInfoService zcglZcdjInfoService;


    @Autowired
    private ZcglZcdjAreaService zcglZcdjAreaService;
    @Autowired
    private ZcglZcdjWarrantService zcglZcdjWarrantService;
    @Autowired
    private ZcglZcdjPhotoService zcglZcdjPhotoService;
//    /**
//     * 列表
//     *
//     * @param
//     * @return
//     */
//    @ApiOperation("获取地址列表")
//    @GetMapping("/getIndex")
//    public ActionResult getIndex() throws IOException {
//        Long htCount = zcglHtglInfoService.count();
//        //根据资产来源取数
//        List<Map<String, Object>> map = zcglHtglInfoService.countByZcSource();
//
//
//
////        return ActionResult.success(list);
//    }
//


    /**
     * 列表
     *
     * @param
     * @return
     */
    @ApiOperation("获取地址列表")
    @GetMapping("/listAddress")
    public ActionResult listAddress() throws IOException {
        List<ZcglZcdjInfoEntity> list = zcglZcdjInfoService.list();
        return ActionResult.success(list);
    }

    /**
     * 列表
     *
     * @param zcglZcdjInfoPagination
     * @return
     */
    @ApiOperation("获取列表")
    @PostMapping("/getList")
    public ActionResult list(@RequestBody ZcglZcdjInfoPagination zcglZcdjInfoPagination) throws IOException {
        System.out.println(zcglZcdjInfoPagination+"正常传参");
        System.out.println(zcglZcdjInfoPagination.getPageSize()+"1111");
        System.out.println(zcglZcdjInfoPagination.getCurrentPage()+"1111");

        List<ZcglZcdjInfoEntity> list = zcglZcdjInfoService.getList(zcglZcdjInfoPagination);
        //处理id字段转名称，若无需转或者为空可删除
        List<ZcglZcdjInfoListVO> listVO = JsonUtil.getJsonToList(list, ZcglZcdjInfoListVO.class);
        System.out.println(listVO.size()+"1111");
        for (ZcglZcdjInfoListVO zcglZcdjInfoVO : listVO) {
            zcglZcdjInfoVO.setZcnumber_name(zcglZcdjInfoVO.getZcnumber());

            zcglZcdjInfoVO.setZcname_name(zcglZcdjInfoVO.getZcname());

            zcglZcdjInfoVO.setZclabel_name(zcglZcdjInfoVO.getZclabel());

            zcglZcdjInfoVO.setAddress_name(zcglZcdjInfoVO.getAddress());

            zcglZcdjInfoVO.setZcnature_name(generaterSwapUtil.getDicName(zcglZcdjInfoVO.getZcnature(), "610823452110094661"));

            zcglZcdjInfoVO.setZcpurpose_name(generaterSwapUtil.getDicName(zcglZcdjInfoVO.getZcpurpose(), "610823865056100677"));

            zcglZcdjInfoVO.setZcsource_name(generaterSwapUtil.getDicName(zcglZcdjInfoVO.getZcsource(), "610823965094445381"));

            zcglZcdjInfoVO.setAffiliatedunit_name(generaterSwapUtil.getDicName(zcglZcdjInfoVO.getAffiliatedunit(), "610824055188095301"));

            zcglZcdjInfoVO.setManagementunit_name(generaterSwapUtil.getDicName(zcglZcdjInfoVO.getManagementunit(), "610824142995849541"));

            zcglZcdjInfoVO.setZcadmin_name(generaterSwapUtil.userSelectValues(zcglZcdjInfoVO.getZcadmin()));

            zcglZcdjInfoVO.setNotes_name(zcglZcdjInfoVO.getNotes());

            zcglZcdjInfoVO.setZcfmimage_name(generaterSwapUtil.getFileNameInJson(zcglZcdjInfoVO.getZcfmimage()));

            zcglZcdjInfoVO.setZcfile_name(generaterSwapUtil.getFileNameInJson(zcglZcdjInfoVO.getZcfile()));

            ZcglZcdjAreaEntity zcglZcdjAreaEntity = zcglZcdjInfoService.getZcglZcdjArea(zcglZcdjInfoVO.getId());
            if (ObjectUtil.isNotEmpty(zcglZcdjAreaEntity)) {
                zcglZcdjInfoVO.setBuildingmeasurementarea(zcglZcdjAreaEntity.getBuildingMeasurementArea());
                ZcglZcdjAreaListVO zcglZcdjAreaListVO = JsonUtil.getJsonToBean(zcglZcdjAreaEntity, ZcglZcdjAreaListVO.class);
                zcglZcdjAreaListVO.setBuildingarea_name(zcglZcdjAreaListVO.getBuildingarea());

                zcglZcdjAreaListVO.setLandarea_name(zcglZcdjAreaListVO.getLandarea());

                zcglZcdjAreaListVO.setSharedlandarea_name(zcglZcdjAreaListVO.getSharedlandarea());

                zcglZcdjAreaListVO.setBuildingmeasurementarea_name(zcglZcdjAreaListVO.getBuildingmeasurementarea());

                zcglZcdjAreaListVO.setLandsurveyarea_name(zcglZcdjAreaListVO.getLandsurveyarea());

                zcglZcdjAreaListVO.setExclusivearea_name(zcglZcdjAreaListVO.getExclusivearea());

                zcglZcdjAreaListVO.setSharedarea_name(zcglZcdjAreaListVO.getSharedarea());

                zcglZcdjInfoVO.setZcgl_zcdj_area(zcglZcdjAreaListVO);
            }
            ZcglZcdjWarrantEntity zcglZcdjWarrantEntity = zcglZcdjInfoService.getZcglZcdjWarrant(zcglZcdjInfoVO.getId());
            if (ObjectUtil.isNotEmpty(zcglZcdjWarrantEntity)) {
                ZcglZcdjWarrantListVO zcglZcdjWarrantListVO = JsonUtil.getJsonToBean(zcglZcdjWarrantEntity, ZcglZcdjWarrantListVO.class);
                zcglZcdjWarrantListVO.setPropertyright_name(generaterSwapUtil.getDicName(zcglZcdjWarrantListVO.getPropertyright(), "610826202277478725"));

                zcglZcdjWarrantListVO.setWarrantnumber_name(zcglZcdjWarrantListVO.getWarrantnumber());

                zcglZcdjWarrantListVO.setLanduse_name(zcglZcdjWarrantListVO.getLanduse());

                zcglZcdjWarrantListVO.setHousepurpose_name(zcglZcdjWarrantListVO.getHousepurpose());

                zcglZcdjWarrantListVO.setZzpropertyowner_name(zcglZcdjWarrantListVO.getZzpropertyowner());

                zcglZcdjWarrantListVO.setXzpropertyowner_name(zcglZcdjWarrantListVO.getXzpropertyowner());

                zcglZcdjWarrantListVO.setAddress_name(zcglZcdjWarrantListVO.getAddress());

                zcglZcdjWarrantListVO.setUsenature_name(generaterSwapUtil.getDicName(zcglZcdjWarrantListVO.getUsenature(), "610826295164535109"));

                zcglZcdjWarrantListVO.setBuildings_name(zcglZcdjWarrantListVO.getBuildings());

                zcglZcdjWarrantListVO.setLayers_name(zcglZcdjWarrantListVO.getLayers());

                zcglZcdjWarrantListVO.setNumberfloors_name(zcglZcdjWarrantListVO.getNumberfloors());

                zcglZcdjWarrantListVO.setStarttime_name(zcglZcdjWarrantListVO.getStarttime());

                zcglZcdjWarrantListVO.setEndtime_name(zcglZcdjWarrantListVO.getEndtime());

                zcglZcdjWarrantListVO.setIssuancetime_name(zcglZcdjWarrantListVO.getIssuancetime());

                zcglZcdjWarrantListVO.setCustodylocation_name(zcglZcdjWarrantListVO.getCustodylocation());

                zcglZcdjWarrantListVO.setNotes_name(zcglZcdjWarrantListVO.getNotes());

                zcglZcdjWarrantListVO.setProductionfile_name(generaterSwapUtil.getFileNameInJson(zcglZcdjWarrantListVO.getProductionfile()));

                zcglZcdjWarrantListVO.setProductionimage_name(generaterSwapUtil.getFileNameInJson(zcglZcdjWarrantListVO.getProductionimage()));

                zcglZcdjInfoVO.setZcgl_zcdj_warrant(zcglZcdjWarrantListVO);
            }
            ZcglZcdjPhotoEntity zcglZcdjPhotoEntity = zcglZcdjInfoService.getZcglZcdjPhoto(zcglZcdjInfoVO.getId());
            if (ObjectUtil.isNotEmpty(zcglZcdjPhotoEntity)) {
                ZcglZcdjPhotoListVO zcglZcdjPhotoListVO = JsonUtil.getJsonToBean(zcglZcdjPhotoEntity, ZcglZcdjPhotoListVO.class);
                zcglZcdjPhotoListVO.setPhototime_name(zcglZcdjPhotoListVO.getPhototime());

                zcglZcdjPhotoListVO.setPhotoimage_name(generaterSwapUtil.getFileNameInJson(zcglZcdjPhotoListVO.getPhotoimage()));

                zcglZcdjInfoVO.setZcgl_zcdj_photo(zcglZcdjPhotoListVO);
            }
            //子表数据转换
        }

        for (ZcglZcdjInfoListVO vo : listVO) {
            FlowTaskEntity flowTaskEntity = generaterSwapUtil.getInfoSubmit(vo.getId(), FlowTaskEntity::getStatus);
            if (flowTaskEntity != null) {
                vo.setFlowState(flowTaskEntity.getStatus());
            } else {
                //如果生效，直接设置流程通过，不然拆分出来的资产没得这个状态 前端显示有问题
                if (vo.getStatus().equals("20")) {
                    vo.setFlowState(2);

                } else {
                    vo.setFlowState(null);

                }
            }
        }
        PageListVO vo = new PageListVO();
        vo.setList(listVO);
        PaginationVO page = JsonUtil.getJsonToBean(zcglZcdjInfoPagination, PaginationVO.class);
        vo.setPagination(page);
        return ActionResult.success(vo);

    }

    /**
     * 列表
     *
     * @param zcglZcdjInfoPagination
     * @return
     */
    @ApiOperation("获取列表")
    @PostMapping("/zcReport")
    public ActionResult zcReport(@RequestBody ZcglZcdjInfoPagination zcglZcdjInfoPagination) throws IOException {
        PageListVO vo = new PageListVO();
        Long offset = (zcglZcdjInfoPagination.getCurrentPage() - 1) * zcglZcdjInfoPagination.getPageSize();
        zcglZcdjInfoPagination.setOffset(offset);
        vo.setList(zcglZcdjInfoService.getReport(zcglZcdjInfoPagination));
        PaginationVO page = JsonUtil.getJsonToBean(zcglZcdjInfoPagination, PaginationVO.class);
        page.setTotal(zcglZcdjInfoService.getReportCount(zcglZcdjInfoPagination));
        vo.setPagination(page);

        return ActionResult.success(vo);

    }
    @PostMapping("/ysReport")
    public ActionResult ysReport(@RequestBody ZcglZcdjInfoPagination zcglZcdjInfoPagination) throws IOException {
        PageListVO vo = new PageListVO();
        Long offset = (zcglZcdjInfoPagination.getCurrentPage() - 1) * zcglZcdjInfoPagination.getPageSize();
        zcglZcdjInfoPagination.setOffset(offset);
        vo.setList(zcglZcdjInfoService.getReportYs(zcglZcdjInfoPagination));
        PaginationVO page = JsonUtil.getJsonToBean(zcglZcdjInfoPagination, PaginationVO.class);
        page.setTotal(zcglZcdjInfoService.getReportCount(zcglZcdjInfoPagination));
        vo.setPagination(page);
        return ActionResult.success(vo);

    }
    private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @PostMapping("/zcReportYs")
    public ActionResult zcReportYs(@RequestBody ZcglZcdjInfoPagination zcglZcdjInfoPagination) throws IOException {
        PageListVO vo = new PageListVO();
        Long offset = (zcglZcdjInfoPagination.getCurrentPage() - 1) * zcglZcdjInfoPagination.getPageSize();
        zcglZcdjInfoPagination.setOffset(offset);
        val reportYs = zcglZcdjInfoService.getReportYs(zcglZcdjInfoPagination);
        System.out.println(reportYs.size()+"傲视");
        for (int i = 0; i < reportYs.size(); i++) {
            val item = reportYs.get(i);
            System.out.println("卡爱是季赛");
            item.setYsQiChuYue(zcglHtglInfoService.getYingShouByHtNoNowYear(item.getContraceNumber()));
            item.setYuSBenQiZengJia(zcglHtglInfoService.getYingShouByHtNoThisMonth(item.getContraceNumber()));
            // 处理日期格式，假设日期格式为 "yyyy-MM-dd"
            String dateStr = item.getAcquiringDate().split("，")[0].trim(); // 取第一个日期
            System.out.println(dateStr+"取得日");
            LocalDate acquiringDate = LocalDate.parse(dateStr, DATE_FORMATTER);

            // 判断日期并设置税率
            LocalDate cutoffDate = LocalDate.of(2016, 4, 30);
            if (acquiringDate.isBefore(cutoffDate) || acquiringDate.isEqual(cutoffDate)) {
                item.setSl("5%"); // 2016年4月30日前（含）税率为5%
            } else {
                item.setSl("9%"); // 2016年4月30日后税率为9%
            }
        }


        vo.setList(reportYs);




        PaginationVO page = JsonUtil.getJsonToBean(zcglZcdjInfoPagination, PaginationVO.class);
        page.setTotal(zcglZcdjInfoService.getReportCountYs(zcglZcdjInfoPagination));
        vo.setPagination(page);

        return ActionResult.success(vo);

    }


    /**
     * 列表
     *
     * @param zcglZcdjInfoPagination
     * @return
     */
    @ApiOperation("获取列表")
    @PostMapping("/list")
    public List listlist(@RequestBody ZcglZcdjInfoPagination zcglZcdjInfoPagination) throws IOException {
        List<ZcglZcdjInfoEntity> list = zcglZcdjInfoService.getList(zcglZcdjInfoPagination);
        //处理id字段转名称，若无需转或者为空可删除
        List<ZcglZcdjInfoListVO> listVO = JsonUtil.getJsonToList(list, ZcglZcdjInfoListVO.class);
        for (ZcglZcdjInfoListVO zcglZcdjInfoVO : listVO) {
            zcglZcdjInfoVO.setZcnumber_name(zcglZcdjInfoVO.getZcnumber());

            zcglZcdjInfoVO.setZcname_name(zcglZcdjInfoVO.getZcname());

            zcglZcdjInfoVO.setZclabel_name(zcglZcdjInfoVO.getZclabel());

            zcglZcdjInfoVO.setAddress_name(zcglZcdjInfoVO.getAddress());

            zcglZcdjInfoVO.setZcnature_name(generaterSwapUtil.getDicName(zcglZcdjInfoVO.getZcnature(), "610823452110094661"));

            zcglZcdjInfoVO.setZcpurpose_name(generaterSwapUtil.getDicName(zcglZcdjInfoVO.getZcpurpose(), "610823865056100677"));

            zcglZcdjInfoVO.setZcsource_name(generaterSwapUtil.getDicName(zcglZcdjInfoVO.getZcsource(), "610823965094445381"));

            zcglZcdjInfoVO.setAffiliatedunit_name(generaterSwapUtil.getDicName(zcglZcdjInfoVO.getAffiliatedunit(), "610824055188095301"));

            zcglZcdjInfoVO.setManagementunit_name(generaterSwapUtil.getDicName(zcglZcdjInfoVO.getManagementunit(), "610824142995849541"));

            zcglZcdjInfoVO.setZcadmin_name(generaterSwapUtil.userSelectValues(zcglZcdjInfoVO.getZcadmin()));

            zcglZcdjInfoVO.setNotes_name(zcglZcdjInfoVO.getNotes());

            zcglZcdjInfoVO.setZcfmimage_name(generaterSwapUtil.getFileNameInJson(zcglZcdjInfoVO.getZcfmimage()));

            zcglZcdjInfoVO.setZcfile_name(generaterSwapUtil.getFileNameInJson(zcglZcdjInfoVO.getZcfile()));

            ZcglZcdjAreaEntity zcglZcdjAreaEntity = zcglZcdjInfoService.getZcglZcdjArea(zcglZcdjInfoVO.getId());
            if (ObjectUtil.isNotEmpty(zcglZcdjAreaEntity)) {
                ZcglZcdjAreaListVO zcglZcdjAreaListVO = JsonUtil.getJsonToBean(zcglZcdjAreaEntity, ZcglZcdjAreaListVO.class);
                zcglZcdjAreaListVO.setBuildingarea_name(zcglZcdjAreaListVO.getBuildingarea());

                zcglZcdjAreaListVO.setLandarea_name(zcglZcdjAreaListVO.getLandarea());

                zcglZcdjAreaListVO.setSharedlandarea_name(zcglZcdjAreaListVO.getSharedlandarea());

                zcglZcdjAreaListVO.setBuildingmeasurementarea_name(zcglZcdjAreaListVO.getBuildingmeasurementarea());

                zcglZcdjAreaListVO.setLandsurveyarea_name(zcglZcdjAreaListVO.getLandsurveyarea());

                zcglZcdjAreaListVO.setExclusivearea_name(zcglZcdjAreaListVO.getExclusivearea());

                zcglZcdjAreaListVO.setSharedarea_name(zcglZcdjAreaListVO.getSharedarea());

                zcglZcdjInfoVO.setZcgl_zcdj_area(zcglZcdjAreaListVO);
            }
            ZcglZcdjWarrantEntity zcglZcdjWarrantEntity = zcglZcdjInfoService.getZcglZcdjWarrant(zcglZcdjInfoVO.getId());
            if (ObjectUtil.isNotEmpty(zcglZcdjWarrantEntity)) {
                ZcglZcdjWarrantListVO zcglZcdjWarrantListVO = JsonUtil.getJsonToBean(zcglZcdjWarrantEntity, ZcglZcdjWarrantListVO.class);
                zcglZcdjWarrantListVO.setPropertyright_name(generaterSwapUtil.getDicName(zcglZcdjWarrantListVO.getPropertyright(), "610826202277478725"));

                zcglZcdjWarrantListVO.setWarrantnumber_name(zcglZcdjWarrantListVO.getWarrantnumber());

                zcglZcdjWarrantListVO.setLanduse_name(zcglZcdjWarrantListVO.getLanduse());

                zcglZcdjWarrantListVO.setHousepurpose_name(zcglZcdjWarrantListVO.getHousepurpose());

                zcglZcdjWarrantListVO.setZzpropertyowner_name(zcglZcdjWarrantListVO.getZzpropertyowner());

                zcglZcdjWarrantListVO.setXzpropertyowner_name(zcglZcdjWarrantListVO.getXzpropertyowner());

                zcglZcdjWarrantListVO.setAddress_name(zcglZcdjWarrantListVO.getAddress());

                zcglZcdjWarrantListVO.setUsenature_name(generaterSwapUtil.getDicName(zcglZcdjWarrantListVO.getUsenature(), "610826295164535109"));

                zcglZcdjWarrantListVO.setBuildings_name(zcglZcdjWarrantListVO.getBuildings());

                zcglZcdjWarrantListVO.setLayers_name(zcglZcdjWarrantListVO.getLayers());

                zcglZcdjWarrantListVO.setNumberfloors_name(zcglZcdjWarrantListVO.getNumberfloors());

                zcglZcdjWarrantListVO.setStarttime_name(zcglZcdjWarrantListVO.getStarttime());

                zcglZcdjWarrantListVO.setEndtime_name(zcglZcdjWarrantListVO.getEndtime());

                zcglZcdjWarrantListVO.setIssuancetime_name(zcglZcdjWarrantListVO.getIssuancetime());

                zcglZcdjWarrantListVO.setCustodylocation_name(zcglZcdjWarrantListVO.getCustodylocation());

                zcglZcdjWarrantListVO.setNotes_name(zcglZcdjWarrantListVO.getNotes());

                zcglZcdjWarrantListVO.setProductionfile_name(generaterSwapUtil.getFileNameInJson(zcglZcdjWarrantListVO.getProductionfile()));

                zcglZcdjWarrantListVO.setProductionimage_name(generaterSwapUtil.getFileNameInJson(zcglZcdjWarrantListVO.getProductionimage()));

                zcglZcdjInfoVO.setZcgl_zcdj_warrant(zcglZcdjWarrantListVO);
            }
            ZcglZcdjPhotoEntity zcglZcdjPhotoEntity = zcglZcdjInfoService.getZcglZcdjPhoto(zcglZcdjInfoVO.getId());
            if (ObjectUtil.isNotEmpty(zcglZcdjPhotoEntity)) {
                ZcglZcdjPhotoListVO zcglZcdjPhotoListVO = JsonUtil.getJsonToBean(zcglZcdjPhotoEntity, ZcglZcdjPhotoListVO.class);
                zcglZcdjPhotoListVO.setPhototime_name(zcglZcdjPhotoListVO.getPhototime());

                zcglZcdjPhotoListVO.setPhotoimage_name(generaterSwapUtil.getFileNameInJson(zcglZcdjPhotoListVO.getPhotoimage()));

                zcglZcdjInfoVO.setZcgl_zcdj_photo(zcglZcdjPhotoListVO);
            }
            //子表数据转换
        }
        for (ZcglZcdjInfoListVO vo : listVO) {
            FlowTaskEntity flowTaskEntity = generaterSwapUtil.getInfoSubmit(vo.getId(), FlowTaskEntity::getStatus);
            if (flowTaskEntity != null) {
                vo.setFlowState(flowTaskEntity.getStatus());
            } else {
                if (vo.getStatus().equals("20")) {
                    vo.setFlowState(30);
                } else {
                    vo.setFlowState(null);
                }

            }
        }
        PageListVO vo = new PageListVO();
        vo.setList(listVO);
        PaginationVO page = JsonUtil.getJsonToBean(zcglZcdjInfoPagination, PaginationVO.class);
        vo.setPagination(page);
        return listVO;

    }

    /**
     * 创建
     *
     * @param crData
     * @return
     */
    @PostMapping
    @Transactional
    @ApiOperation("创建")
    public ActionResult create(@RequestBody Map<String, Object> crData) throws DataException {
        String title = crData.get("title").toString();

        ZcglZcdjInfoForm zcglZcdjInfoForm = JsonUtil.getJsonToBean(crData, ZcglZcdjInfoForm.class);
        boolean b = zcglZcdjInfoService.checkForm(zcglZcdjInfoForm, 0);
        if (b) {
            return ActionResult.fail("单行输入不能重复");
        }
        String visualId = "638738432952112261";
        VisualdevEntity visualdevEntity = generaterSwapUtil.getVisualEntity(visualId);
        String mainId = RandomUtil.uuId();

        UserInfo userInfo = userProvider.get();
        UserEntity userEntity = generaterSwapUtil.getUser(zcglZcdjInfoForm.getZcAdmin());
        ZcglZcdjInfoEntity entity = JsonUtil.getJsonToBean(zcglZcdjInfoForm, ZcglZcdjInfoEntity.class);
        entity.setCreatoruserid(userInfo.getUserId());
        entity.setCreatortime(new Date());
        entity.setId(mainId);
        if(userEntity!=null){
            entity.setZcAdmin(userEntity.getAccount());

        }
        zcglZcdjInfoService.save(entity);

        //子表数据
        if (ObjectUtil.isNotEmpty(zcglZcdjInfoForm.getZcgl_zcdj_area())) {
            ZcglZcdjAreaEntity zcgl_zcdj_areaentity = JsonUtil.getJsonToBean(zcglZcdjInfoForm.getZcgl_zcdj_area(), ZcglZcdjAreaEntity.class);

            //自动生成的字段
            zcgl_zcdj_areaentity.setParentId(entity.getId());
            zcgl_zcdj_areaentity.setId(mainId);
            zcgl_zcdj_areaentity.setCreatoruserid(userInfo.getUserId());
            zcgl_zcdj_areaentity.setCreatortime(new Date());
            zcglZcdjAreaService.save(zcgl_zcdj_areaentity);
        }
        if (ObjectUtil.isNotEmpty(zcglZcdjInfoForm.getZcgl_zcdj_warrant())) {
            ZcglZcdjWarrantEntity zcgl_zcdj_warrantentity = JsonUtil.getJsonToBean(zcglZcdjInfoForm.getZcgl_zcdj_warrant(), ZcglZcdjWarrantEntity.class);

            //自动生成的字段
            zcgl_zcdj_warrantentity.setParentId(entity.getId());
            zcgl_zcdj_warrantentity.setId(mainId);
            zcgl_zcdj_warrantentity.setCreatoruserid(userInfo.getUserId());
            zcgl_zcdj_warrantentity.setCreatortime(new Date());
            zcglZcdjWarrantService.save(zcgl_zcdj_warrantentity);
        }
        if (ObjectUtil.isNotEmpty(zcglZcdjInfoForm.getZcgl_zcdj_photo())) {
            ZcglZcdjPhotoEntity zcgl_zcdj_photoentity = JsonUtil.getJsonToBean(zcglZcdjInfoForm.getZcgl_zcdj_photo(), ZcglZcdjPhotoEntity.class);

            //自动生成的字段
            zcgl_zcdj_photoentity.setParentId(entity.getId());
            zcgl_zcdj_photoentity.setId(mainId);
            zcgl_zcdj_photoentity.setCreatoruserid(userInfo.getUserId());
            zcgl_zcdj_photoentity.setCreatortime(new Date());
            zcglZcdjPhotoService.save(zcgl_zcdj_photoentity);
        }
        if (FlowStatusEnum.submit.getMessage().equals(zcglZcdjInfoForm.getStatus())) {
            try {
                visualdevEntity.setFullName(title);
                generaterSwapUtil.submitFlowTask(visualdevEntity, mainId, zcglZcdjInfoForm, userInfo, zcglZcdjInfoForm.getCandidateList(), zcglZcdjInfoForm.getFlowUrgent());
            } catch (WorkFlowException e) {
                e.printStackTrace();
            }
            return ActionResult.success("提交成功，请耐心等待");
        }
        return ActionResult.success("保存成功");
    }


    /**
     * 信息
     *
     * @param id
     * @return
     */
    @ApiOperation("信息")
    @GetMapping("/{id}")
    public ActionResult<ZcglZcdjInfoInfoVO> info(@PathVariable("id") String id) {
        ZcglZcdjInfoEntity entity = zcglZcdjInfoService.getInfo(id);
        ZcglZcdjInfoInfoVO vo = JsonUtil.getJsonToBean(entity, ZcglZcdjInfoInfoVO.class);
        //将管理员名称设置为中文
//        vo.setZcAdmin(generaterSwapUtil.getUser(vo.getZcAdmin()).getAccount());
        //子表
        //副表
        QueryWrapper<ZcglZcdjAreaEntity> queryWrapperZcglZcdjArea = new QueryWrapper<>();
        queryWrapperZcglZcdjArea.lambda().eq(ZcglZcdjAreaEntity::getParentId, entity.getId());
        ZcglZcdjAreaEntity zcgl_zcdj_areaEntity = zcglZcdjAreaService.getOne(queryWrapperZcglZcdjArea);
        ZcglZcdjAreaModel zcglZcdjAreaModel = JsonUtil.getJsonToBean(zcgl_zcdj_areaEntity, ZcglZcdjAreaModel.class);
        vo.setZcgl_zcdj_area(zcglZcdjAreaModel);
        QueryWrapper<ZcglZcdjWarrantEntity> queryWrapperZcglZcdjWarrant = new QueryWrapper<>();
        queryWrapperZcglZcdjWarrant.lambda().eq(ZcglZcdjWarrantEntity::getParentId, entity.getId());
        ZcglZcdjWarrantEntity zcgl_zcdj_warrantEntity = zcglZcdjWarrantService.getOne(queryWrapperZcglZcdjWarrant);
        ZcglZcdjWarrantModel zcglZcdjWarrantModel = JsonUtil.getJsonToBean(zcgl_zcdj_warrantEntity, ZcglZcdjWarrantModel.class);
        vo.setZcgl_zcdj_warrant(zcglZcdjWarrantModel);
        QueryWrapper<ZcglZcdjPhotoEntity> queryWrapperZcglZcdjPhoto = new QueryWrapper<>();
        queryWrapperZcglZcdjPhoto.lambda().eq(ZcglZcdjPhotoEntity::getParentId, entity.getId());
        ZcglZcdjPhotoEntity zcgl_zcdj_photoEntity = zcglZcdjPhotoService.getOne(queryWrapperZcglZcdjPhoto);
        ZcglZcdjPhotoModel zcglZcdjPhotoModel = JsonUtil.getJsonToBean(zcgl_zcdj_photoEntity, ZcglZcdjPhotoModel.class);
        if(ObjectUtil.isEmpty(zcglZcdjPhotoModel)){
            zcglZcdjPhotoModel = new ZcglZcdjPhotoModel();
        }
        vo.setZcgl_zcdj_photo(zcglZcdjPhotoModel);
        return ActionResult.success(vo);
    }


    /**
     * 更新
     *
     * @param id
     * @param upData
     * @return
     */
    @PutMapping("/{id}")
    @Transactional
    @ApiOperation("更新")
    public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid Map<String, Object> upData) throws DataException {
        ZcglZcdjInfoForm zcglZcdjInfoForm = JsonUtil.getJsonToBean(upData, ZcglZcdjInfoForm.class);
        boolean b = zcglZcdjInfoService.checkForm(zcglZcdjInfoForm, 1);
        if (b) {
            return ActionResult.fail("单行输入不能重复");
        }
        String visualId = "638738432952112261";
        VisualdevEntity visualdevEntity = generaterSwapUtil.getVisualEntity(visualId);
        UserInfo userInfo = userProvider.get();
        ZcglZcdjInfoEntity entity = zcglZcdjInfoService.getInfo(id);
        if (entity != null) {
            ZcglZcdjInfoEntity subentity = JsonUtil.getJsonToBean(zcglZcdjInfoForm, ZcglZcdjInfoEntity.class);
            boolean b1 = zcglZcdjInfoService.updateById(subentity);
            if (!b1) {
                return ActionResult.fail("当前表单原数据已被调整，请重新进入该页面编辑并提交数据");
            }
            //子表数据
            if (ObjectUtil.isNotEmpty(zcglZcdjInfoForm.getZcgl_zcdj_area())) {
                QueryWrapper<ZcglZcdjAreaEntity> queryWrapperZcglZcdjArea = new QueryWrapper<>();
                queryWrapperZcglZcdjArea.lambda().eq(ZcglZcdjAreaEntity::getParentId, entity.getId());
                ZcglZcdjAreaEntity zcgl_zcdj_areaOneEntity = zcglZcdjAreaService.getOne(queryWrapperZcglZcdjArea);
                ZcglZcdjAreaEntity zcgl_zcdj_areaentity = JsonUtil.getJsonToBean(zcglZcdjInfoForm.getZcgl_zcdj_area(), ZcglZcdjAreaEntity.class);
                zcgl_zcdj_areaentity.setId(zcgl_zcdj_areaOneEntity.getId());
                zcgl_zcdj_areaentity.setParentId(entity.getId());
                zcglZcdjAreaService.updateById(zcgl_zcdj_areaentity);
            }
            if (ObjectUtil.isNotEmpty(zcglZcdjInfoForm.getZcgl_zcdj_warrant())) {
                QueryWrapper<ZcglZcdjWarrantEntity> queryWrapperZcglZcdjWarrant = new QueryWrapper<>();
                queryWrapperZcglZcdjWarrant.lambda().eq(ZcglZcdjWarrantEntity::getParentId, entity.getId());
                ZcglZcdjWarrantEntity zcgl_zcdj_warrantOneEntity = zcglZcdjWarrantService.getOne(queryWrapperZcglZcdjWarrant);
                ZcglZcdjWarrantEntity zcgl_zcdj_warrantentity = JsonUtil.getJsonToBean(zcglZcdjInfoForm.getZcgl_zcdj_warrant(), ZcglZcdjWarrantEntity.class);
                zcgl_zcdj_warrantentity.setId(zcgl_zcdj_warrantOneEntity.getId());
                zcgl_zcdj_warrantentity.setParentId(entity.getId());
                zcglZcdjWarrantService.updateById(zcgl_zcdj_warrantentity);
            }
            if (ObjectUtil.isNotEmpty(zcglZcdjInfoForm.getZcgl_zcdj_photo())) {


                QueryWrapper<ZcglZcdjPhotoEntity> queryWrapperZcglZcdjPhoto = new QueryWrapper<>();
                queryWrapperZcglZcdjPhoto.lambda().eq(ZcglZcdjPhotoEntity::getParentId, entity.getId());
                ZcglZcdjPhotoEntity zcgl_zcdj_photoOneEntity = zcglZcdjPhotoService.getOne(queryWrapperZcglZcdjPhoto);
                ZcglZcdjPhotoEntity zcgl_zcdj_photoentity = JsonUtil.getJsonToBean(zcglZcdjInfoForm.getZcgl_zcdj_photo(), ZcglZcdjPhotoEntity.class);

                if(zcgl_zcdj_photoOneEntity!=null){
                    zcgl_zcdj_photoentity.setId(zcgl_zcdj_photoOneEntity.getId());
                    zcgl_zcdj_photoentity.setParentId(entity.getId());
                    zcglZcdjPhotoService.updateById(zcgl_zcdj_photoentity);
                }

            }
            if (FlowStatusEnum.submit.getMessage().equals(zcglZcdjInfoForm.getStatus())) {
                try {
                    generaterSwapUtil.submitFlowTask(visualdevEntity, id, subentity, userInfo, zcglZcdjInfoForm.getCandidateList(), zcglZcdjInfoForm.getFlowUrgent());
                } catch (WorkFlowException e) {
                    e.printStackTrace();
                }
                return ActionResult.success("提交成功，请耐心等待");
            }
            return ActionResult.success("更新成功");
        } else {
            return ActionResult.fail("更新失败，数据不存在");
        }
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    @Transactional
    public ActionResult delete(@PathVariable("id") String id) {
        ZcglZcdjInfoEntity entity = zcglZcdjInfoService.getInfo(id);
        if (entity != null) {
            FlowTaskEntity taskEntity = generaterSwapUtil.getInfoSubmit(id, FlowTaskEntity::getId, FlowTaskEntity::getStatus);
            if (taskEntity != null) {
                try {
                    generaterSwapUtil.deleteFlowTask(taskEntity);
                } catch (WorkFlowException e) {
                    e.printStackTrace();
                }
            }
            zcglZcdjInfoService.delete(entity);
            //子表数据
            QueryWrapper<ZcglZcdjAreaEntity> queryWrapperZcglZcdjArea = new QueryWrapper<>();
            queryWrapperZcglZcdjArea.lambda().eq(ZcglZcdjAreaEntity::getParentId, entity.getId());
            zcglZcdjAreaService.remove(queryWrapperZcglZcdjArea);
            QueryWrapper<ZcglZcdjWarrantEntity> queryWrapperZcglZcdjWarrant = new QueryWrapper<>();
            queryWrapperZcglZcdjWarrant.lambda().eq(ZcglZcdjWarrantEntity::getParentId, entity.getId());
            zcglZcdjWarrantService.remove(queryWrapperZcglZcdjWarrant);
            QueryWrapper<ZcglZcdjPhotoEntity> queryWrapperZcglZcdjPhoto = new QueryWrapper<>();
            queryWrapperZcglZcdjPhoto.lambda().eq(ZcglZcdjPhotoEntity::getParentId, entity.getId());
            zcglZcdjPhotoService.remove(queryWrapperZcglZcdjPhoto);

        }
        return ActionResult.success("删除成功");
    }

    @ApiOperation("资产登记审批通过执行")
    @PostMapping("/operate/action")
    public ActionResult<?> operateAction(@RequestBody ZcglZcdjInfoForm form) {
        zcglZcdjInfoService.operateAction(form.getId());
        return ActionResult.success();
    }

    @ApiOperation("资产登记基础数据变更")
    @PostMapping("/zcdjInfo/change")
    public ActionResult<?> zcdjInfoChange(@RequestBody ZcglZcdjInfoChangeEntity entity) throws DataException {
        zcglZcdjInfoService.zcdjInfoChange(entity);
        return ActionResult.success();
    }

    @ApiOperation("资产登记基础数据变更（拆分）")
    @PostMapping("/zcdjInfo/changeSplit")
    public ActionResult<?> changeSplit(@RequestBody List<ZcglZcdjInfoChangeEntity> entitys) {
        zcglZcdjInfoService.zcdjInfoChangeSplit(entitys);
        return ActionResult.success();
    }

    @ApiOperation("面积接口")
    @PostMapping("/getArea")
    public ActionResult<?> getArea() {

        // 将结果封装到 Map 中
        Map<String, Double> areaSums = new HashMap<>();
        areaSums = zcglZcdjAreaService.calculateAreaSums();
        // 返回成功结果
        return ActionResult.success(areaSums);
    }

    /**
     * 下载导出模版
     * @param response
     * @throws IOException
     */
    @ApiOperation("下载导出模版")
    @GetMapping("/downloadTemplate")
    public void downloadTemplate(HttpServletResponse response) throws IOException {
        // 创建一个空的模板数据
        List<ZcglZcdjInfoInfoPoiDTO> dataList = new ArrayList<>();
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("资产登记模板", "信息表"), ZcglZcdjInfoInfoPoiDTO.class, dataList);

        // 设置响应头，指定下载文件名
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename=zcdj_info_template.xlsx");

        // 输出模板文件到浏览器
        workbook.write(response.getOutputStream());
        workbook.close();
    }

    /**
     * 导出
     * @param response
     * @throws Exception
     */
    @ApiOperation("导出")
    @PostMapping("/export")
    public void exportExcel(@RequestBody ZcglZcdjInfoPagination zcglZcdjInfoPagination,HttpServletResponse response) throws Exception {
        zcglZcdjInfoService.exportExcel(zcglZcdjInfoPagination,response);
    }

    /**
     * 导入
     * @param file
     * @return
     * @throws Exception
     */
    @ApiOperation("导入")
    @PostMapping("/import")
    public ActionResult<?> importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        return zcglZcdjInfoService.importExcel(file);
    }

}
